<?php

/**
 * 后台网址设置
 * @author  xiaobai
 * @date    2017-01-08
 */

namespace app\panel\controller;

use app\common\controller\Panelbase;
use think\facade\Env;

class Site extends Panelbase
{
    public function initialize()
    {
        parent::initialize();
        $this->model = model('Common/Site');
    }

    /**
     * 网站前台基本信息设置
     *
     * @date   17-01-08
     * @author xiaobai
     */
    public function setting()
    {
        $row = $this->model->find();

        $this->assign($row);
        return $this->fetch();
    }

    /**
     * 网站前台基本执行
     *
     * @date   17-01-08
     * @author xiaobai
     */
    public function setting_post()
    {
        if (request()->isPost()) {
            $data  = input('post.');
            $where = array('id'=>1);
            $res = $this->model->siteSave($data, $where);
            if ($res != false) {
                $this->success('保存成功', Url('setting'));
            } else {
                $this->error('保存失败');
            }
        } else {
            $this->error('请求错误');
        }
    }

    /**
     * 清理缓存
     *
     * @date    17-07-16
     * @author  xiaobai
     */
    public function clear_cache()
    {
        $url  = $_SERVER['HTTP_REFERER'];
        $runtime_path = Env::get('runtime_path');
        $rtim = del_dir_and_file($runtime_path);
        if ($rtim) {
            $this->success('清除成功', $url);
        } else {
            $this->error('清除失败');
        }
    }

}
